package fr.umlv.m2.jee.pmlv.persistence.ldapLink.dao;

import java.util.List;
import org.springframework.stereotype.Repository;

import fr.umlv.m2.jee.pmlv.framework.dao.hibernate.AbstractHibernateDAO;
import fr.umlv.m2.jee.pmlv.persistence.ldapLink.UserSpecialty;
import fr.umlv.m2.jee.pmlv.persistence.ldapLink.UserSpecialtyPK;

@Repository("hibernateUserSpecialtyDAO")
public class HibernateUserSpecialtyDAO
				extends AbstractHibernateDAO<UserSpecialtyPK, UserSpecialty >  
				implements IUserSpecialtyDAO {
    
    @Override
    public List<UserSpecialty> findByUserUidAndByYear(String uid, int year) {
            String query = "from UserSpecialty as us where us.primaryKey.uid = '"+uid+"' and us.primaryKey.year="+year;
            return findByQuery(query);
    }

    @Override
    public List<UserSpecialty> findBySubjectIdAndByYear(Long id, int year) {
        String query = "select distinct us from UserSpecialty as us, Specialty as s "
                + "inner join s.specialtySubject as sub "
                + "where s.id=us.primaryKey.specialty.id and us.primaryKey.year="+year+" and sub.subject.id="+id;
        return findByQuery(query);
    }

    @Override
    public List<UserSpecialty> findByUserUid(String uid) {
            String query = "from UserSpecialty as us where us.primaryKey.uid = '"+uid+"'";
            return findByQuery(query);
    }
}